# input() 输入
message = input("Tell me something, and I will repeat it back to you:")
print(message)

promt = "if you share your name, we can personalize the messages you see."
promt += "\nwhat is you firt name?"
name = input(promt)
print(name)

# 使用 int()获取数值输入   input()默认为字符串输入
age = input("how old are you?")
print(age)
print(type(age))
age = int(age)
print(age)
print(type(age))

#求模运算
print(4 % 3)
print(5 % 3)

# while 循环
current_number = 1
while current_number <= 5:
    print(current_number)
    current_number += 1

# 让用户选择何时退出
promt = "\nTell me something, and I will repeat it back to you:"
promt += "\nEnter 'quit' to end the program."
message = ""
while message != "quit":
    message = input(promt).lower()
    if message != "quit":
        print(message)

# 使用标志控制退出
promt = "\nTell me something, and I will repeat it back to you:"
promt += "\nEnter 'quit' to end the program."

active = True
while active:
    message = input(promt)
    if message == "quit":
        active = False
    else:
        print(message)

# 使用break退出循环
promt = "\nTell me something, and I will repeat it back to you:"
promt += "\nEnter 'quit' to end the program."

while True:
    city = input(promt)
    if city == "quit":
        break
    else:
        print(f"I'd love to go to {city.title()}")

# 循环中使用 continue
current_number = 0
while current_number < 10:
    current_number += 1
    if current_number % 2 == 0:
        continue
    print(current_number)

# 使用 while循环处理列表和元素
## 列表之间移动元素
unconfirmed_users = ["alice", "brian", "candace"]
confirmed_users = []
while unconfirmed_users:
    current_user = unconfirmed_users.pop()
    print(f"Verifying user {current_user}")
    confirmed_users.append(current_user)
print("\nThe following users have been confirmed:")
for confirmed_user in confirmed_users:
    print(confirmed_user)

## 删除为特定值的所有列表元素
pets = ["dog", "cat", "dog", "goldfish", "cat", "rabbit", "cat"]
print(pets)

while "cat" in pets:
    pets.remove("cat")
print(pets)

## 使用用户输入填充字典
responses = {}
polling_active = True
while polling_active:
    name = input("\n What is your name?")
    response = input("which mountain would you like to climb someday?")
    responses[name] = response

    repeat = input("would you like to let another person respond?(yes/no)")
    if repeat == "no":
        polling_active = False
print("\n --- Poll Results ---")
print(responses)
for key,value in responses.items():
    print(f"{key} would lite to climb {value}")
print(name) # python 没有块级作用域
